package com.smartjobs.model;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.smartjobs.bean.CompanyBean;
import com.smartjobs.bean.JobPostingBean;
import com.smartjobs.util.DBManager;

public class EditCompanyProfileModel {

	public static void UpdateProfile(CompanyBean company) {
		String query = "UPDATE `smartjobs`.`companyprofile` SET `companyName`='"
				+ company.getCompanyName()
				+ "', `emailId`='"
				+ company.getEmailID()
				+ "', `phoneNumber`='"
				+ company.getPhoneNumber()
				+ "' WHERE `companyId`='"
				+ company.getCompanyID() + "';";
		DBManager.updateTable(query);
	}

	public static void InsertJobPosting(JobPostingBean jobposting) {

		String query = "INSERT INTO `smartjobs`.`jobposting` "
				+ "(`jobCode`, `jobDesc`, `location`, `companyId`, `qualification`) "
				+ "VALUES ('" + jobposting.getJobCode() + "', '"
				+ jobposting.getJobDesc() + "', '" + jobposting.getLocation()
				+ "', '" + jobposting.getCompanyId() + "', '"
				+ jobposting.getQualification() + "');";

		DBManager.insertIntoDB(query);

	}

	public static void InsertJobPostingSkills(int jobID, int skillID) {
		String query = "INSERT INTO `smartjobs`.`jobposting_skills` (`jobId`, `skillId`) VALUES ('"
				+ jobID + "', '" + skillID + "');";
		DBManager.insertIntoDB(query);
	}

	public static int FindJobID(String jobCode, int companyID) {
		String query = "SELECT * FROM smartjobs.jobposting where jobCode = '"
				+ jobCode + "' and companyID = '" + companyID + "';";
		ResultSet result = DBManager.selectFromDB(query);
		try {
			if (result.next())
				return result.getInt("jobId");

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return 0;

	}
}
